package model

import (
	"database/sql/driver"
	"encoding/json"
	"gorm.io/gorm"
	"time"
)

type GormList []string

func (g GormList) Value() (value driver.Value, err error) {
	return json.Marshal(g)
}

// 实现sql.Scanner接口,scan将value扫描到jsonb
func (g GormList) Scan(value interface{}) error {
	return json.Unmarshal(value.([]byte), &g)
}

type BaseModel struct {
	ID        int32          `gorm:"primaryKey;type:int" json:"id"`
	CreatedAt time.Time      `gorm:"column:add_time" json:"createdAt"`
	UpdatedAt time.Time      `gorm:"column:update_time" json:"updatedAt"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"-"`
	IsDeleted bool           `gorm:"column:is_deleted" json:"isDeleted"`
}
